home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_024 / conquest / conq4.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  11KB  |  267 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3. #include "structs.h"
  4. #include "vars.h"
  5.  
  6. tf_battle(starnum)
  7. int starnum;
  8. {
  9.         int ennum,plnum; 
  10.         float enodds,plodds; 
  11.         boolean battle;
  12.         int count,new_tf,i;  
  13.         char ch;
  14.         boolean pla_loss,ene_loss;
  15.         int size; 
  16.         tteam team;
  17.         int dstar;
  18.         float slist[nstars+1];
  19.         boolean fin, first;
  20.         board[stars[starnum].x][ stars[starnum].y].enemy = '!';
  21.         update_board(stars[starnum].x, stars[starnum].y, left);
  22.         ennum=1;
  23.         while ((tf[ENEMY][ennum].dest!=starnum)||(tf[ENEMY][ennum].eta!=0)
  24.             ) ennum = ennum+1;
  25.         plnum=1;
  26.         if ( tf_stars[starnum][player]>1 ) {
  27.                 get_tf(player,&new_tf,starnum);
  28.                 for ( i= 1 ; i<=26; i++ ) {
  29.                         if ( (tf[player][i].dest == starnum) && (tf[player][i].eta==0)
  30.                             && (i != new_tf) )
  31.                                 joinsilent(player, &tf[player][new_tf],&tf[player][i]);
  32.                 };
  33.                 tf_stars[starnum][player] = 1;
  34.                 plnum=new_tf;
  35.         } 
  36.         else {
  37.                 while ((tf[player][plnum].dest!=starnum)||(tf[player][plnum].eta!=0)
  38.                     ) plnum=plnum+1;
  39.         };
  40.         display_forces(ennum,plnum,&enodds,&plodds,&battle);
  41.         pause();
  42.         first = true;
  43.         while ( battle ) {
  44.                 if ( left_line[24] ) {
  45.                         point(1,24);
  46.                         printf(blank_line);
  47.                         left_line[24] = false;
  48.                 };
  49.                 pla_loss = true;
  50.                 ene_loss = true;
  51.                 point(1,21);
  52.                 printf(" Enemy losses:                ");
  53.                 point(1,22);
  54.                 printf("Player losses:                ");
  55.                 do {
  56.                         point(15,21);
  57.                         lose(&tf[ENEMY][ennum].t,&ene_loss,'t',enodds);
  58.                         lose(&tf[ENEMY][ennum].s,&ene_loss,'s',enodds);
  59.                         lose(&tf[ENEMY][ennum].c,&ene_loss,'c',enodds);
  60.                         lose(&tf[ENEMY][ennum].b,&ene_loss,'b',enodds);
  61.                         point(15,22);
  62.                         lose(&tf[player][plnum].t,&pla_loss,'t',plodds);
  63.                         lose(&tf[player][plnum].s,&pla_loss,'s',plodds);
  64.                         lose(&tf[player][plnum].c,&pla_loss,'c',plodds);
  65.                         lose(&tf[player][plnum].b,&pla_loss,'b',plodds);
  66.                 } 
  67.                 while (!first && ene_loss && pla_loss);
  68.                 if ( ene_loss ) {
  69.                         point(15,21);
  70.                         printf("(none)");
  71.                 };
  72.                 if ( pla_loss ) {
  73.                         point(15,22);
  74.                         printf("(none)");
  75.                 };
  76.                 first = false;
  77.                 display_forces(ennum,plnum,&enodds,&plodds,&battle);
  78.                 if ( battle ) {
  79.                         /*withdraw the bad guys*/
  80.                         get_tf(ENEMY,&new_tf,starnum);
  81.                         if ( (tf[player][plnum].c>0) || (tf[player][plnum].b>0)
  82.                             ) {
  83.                                 tf[ENEMY][new_tf].t = tf[ENEMY][ennum].t;
  84.                                 tf[ENEMY][new_tf].s = tf[ENEMY][ennum].s;
  85.                                 best_plan(&starnum,&size,&team);
  86.                                 if ( ((enodds<0.7) && (size<30) )|| ((enodds<0.50)
  87.                                     && (team==player)) || ((enodds <0.30) && (size < 60)) 
  88.                                         || (enodds < 0.20)  ) {
  89.                                         tf[ENEMY][new_tf].c = tf[ENEMY][ennum].c;
  90.                                         tf[ENEMY][new_tf].b = tf[ENEMY][ennum].b;
  91.                                 };
  92.                         };
  93.                         if((tf[ENEMY][new_tf].t + tf[ENEMY][new_tf].s +
  94.                                 tf[ENEMY][new_tf].c + tf[ENEMY][new_tf].b) > 0) {
  95.                                 get_stars(starnum,slist,&count);
  96.                                 do {
  97.                                         dstar = rnd(nstars);
  98.                                 } 
  99.                                 while (slist[dstar] <= 0);
  100.                                 tf[ENEMY][new_tf].dest = dstar;
  101.                                 tf[ENEMY][new_tf].eta = (int)((slist[dstar]-0.01)/vel[ENEMY])+1;
  102.                                 tf[ENEMY][new_tf].xf=stars[starnum].x;
  103.                                 tf[ENEMY][new_tf].yf=stars[starnum].y;
  104.                         } 
  105.                         else tf[ENEMY][new_tf].dest = 0;
  106.  
  107.                         fin = false;
  108.                         do {
  109.                                 point(1,18);
  110.                                 printf("B?                            ");
  111.                                 point(3,18);
  112.                                 get_char(&ch);
  113.                                 switch ( ch ) {
  114.                                 case 'M':
  115.                                         printmap();
  116.                                         break;
  117.                                 case 'H': 
  118.                                         help(2);
  119.                                         break;
  120.                                 case 'S':
  121.                                         starsum();
  122.                                         break;
  123.                                 case 'T': 
  124.                                         tfsum();
  125.                                         break;
  126.                                 case 'C':
  127.                                         print_col();
  128.                                         break;
  129.                                 case '?': 
  130.                                         break;
  131.                                 case 'R':
  132.                                         ressum();
  133.                                         break;
  134.                                 case 'O': 
  135.                                         display_forces(ennum,plnum,&enodds, &plodds, &battle);
  136.                                         break;
  137.                                 case 'W': 
  138.                                         withdraw(starnum,plnum);
  139.                                         display_forces(ennum,plnum,&enodds,&plodds,&battle);
  140.                                         break;
  141.                                 case ' ': 
  142.                                 case 'G': 
  143.                                         fin = true;
  144.                                         break;
  145.                                 default: 
  146.                                         printf("!illegal command");
  147.                                 }; /*switch (*/
  148.                         } 
  149.                         while (!fin && battle);
  150.                         zero_tf(ENEMY,new_tf);
  151.                         zero_tf(player,plnum);
  152.                         if ( tf[ENEMY][new_tf].dest != 0 ) {
  153.                                 point(1,23);
  154.                                 printf("en withdraws");
  155.                                 point(14,23);
  156.                                 disp_tf(&tf[ENEMY][new_tf]);
  157.                                 tf[ENEMY][ennum].t = tf[ENEMY][ennum].t - tf[ENEMY][new_tf].t;
  158.                                 tf[ENEMY][ennum].s = tf[ENEMY][ennum].s - tf[ENEMY][new_tf].s;
  159.                                 tf[ENEMY][ennum].c = tf[ENEMY][ennum].c - tf[ENEMY][new_tf].c;
  160.                                 tf[ENEMY][ennum].b = tf[ENEMY][ennum].b - tf[ENEMY][new_tf].b;
  161.                                 zero_tf(ENEMY,ennum);
  162.                                 display_forces (ennum,plnum,&enodds,&plodds,&battle);
  163.                         };
  164.                 };
  165.         };
  166.         zero_tf(ENEMY,ennum);
  167.         zero_tf(player,plnum);
  168.         revolt(starnum);
  169.         on_board(stars[starnum].x,stars[starnum].y);
  170. }
  171.  
  172. update_board(x, y, option)
  173. toption option;
  174. {
  175.         int scren_x, screen_y;
  176.         if ( terminal_type != hardcopy ) {
  177.                 scren_x = 3*x + 1;
  178.                 screen_y = 16 - y;
  179.                 switch ( option ) {
  180.                 case left:
  181.                         point(scren_x,screen_y);
  182.                         putchar(board[x][y].enemy);
  183.                         break;
  184.  
  185.                 case right:
  186.                         point(scren_x+2,screen_y);
  187.                         putchar(board[x][y].tf);
  188.                         break;
  189.  
  190.                 case both:
  191.                         point(scren_x, screen_y);
  192.                         printf("%c%c%c", board[x][y].enemy,board[x][y].star, board[x][y].tf);
  193.                         break;
  194.                 }; /*switch (*/
  195.         };
  196. }
  197.  
  198.  
  199. up_year()
  200. {
  201.         point(39,18);
  202.         turn = turn + 1;
  203.         if ( terminal_type == hardcopy )
  204.                 printf("Year ");
  205.         printf("%3d", turn);
  206.         point(48,19);
  207.         production_year = production_year + 1;
  208.         if ( terminal_type == hardcopy )
  209.                 printf("Production year ");
  210.         printf("%d", production_year);
  211. }
  212.  
  213. withdraw(starnum, plnum)
  214. {
  215.         int withnum;  
  216.         boolean error;
  217.         printf("ithdraw ");
  218.         cle3r_left();
  219.         point(1,19);
  220.         split_tf(&plnum,&withnum);
  221.         if ( tf[player][withnum].dest != 0 ) {
  222.                 point(1,20);
  223.                 set_des(withnum,&error);
  224.                 if ( error ) {
  225.                         tf[player][plnum].dest=starnum;
  226.                         joinsilent(player,&tf[player][plnum],
  227.                                                         &tf[player][withnum]);
  228.                         tf_stars[starnum][player] = 1;
  229.                 } 
  230.                 else
  231.                         tf[player][withnum].withdrew = true;
  232.         };
  233. }
  234.  
  235. zero_tf(tm, tf_num)
  236. tteam tm;
  237. {
  238.         int x,y, i;
  239.         if ( tf[tm][tf_num].dest != 0 ) {
  240.                 x= tf[tm][tf_num].x;  
  241.                 y= tf[tm][tf_num].y;
  242.                 if ( (tf[tm][tf_num].s+tf[tm][tf_num].t + tf[tm][tf_num].c +
  243.                     tf[tm][tf_num].b ) ==0 ) {
  244.                         if ( tf[tm][tf_num].eta==0 ) {
  245.                                 tf_stars[tf[tm][tf_num].dest][tm]--;
  246.                         };
  247.                         tf[tm][tf_num].dest=0;
  248.                         if(tm==player) {
  249.                                 board[x][y].tf=' ';
  250.                                 for(i=1; i<=26; i++) {
  251.                                         if((tf[player][i].dest !=0) &&
  252.                                                 (tf[player][i].x == x) &&
  253.                                                 (tf[player][i].y == y)) {
  254.                                                 if(board[x][y].tf == ' ')
  255.                                                         board[x][y].tf = i + 'a' - 1;
  256.                                                 else
  257.                                                         board[x][y].tf = '*';
  258.                                         };
  259.                                 }
  260.                                 update_board(x,y,right);
  261.                         }
  262.  
  263.                 };
  264.         };
  265. }
  266.  
  267.